<%@page import="co.gov.medellin.ssti.sub.model.dao.exception.DAOException"%>
<%@page import="co.gov.medellin.ssti.sub.model.vo.AreaVO"%>
<%@page import="co.gov.medellin.ssti.sub.model.vo.ProgramaVO"%>
<%@page import="java.util.Collection"%>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic"%>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%>
<%@ taglib uri="/WEB-INF/displaytag.tld" prefix="display"%>
<%@ page contentType="text/html;charset=utf-8"%>

<script type="text/javascript"
	src="<%=request.getContextPath() + "/js/popUPdesc.js"%>"></script>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="<%=request.getContextPath() + "/css/bloques.css"%>"
	rel="stylesheet" type="text/css">
<title>Consultar Subprograma</title>

<script type="text/javascript">
	function fConsultar() {
		document.form.submit();
	}

	function flimpiar() {
		document.form.subprograma.value = "";
		document.form.secretaria.value = "";
	}
	function flimpiar1() {
		document.form.subprograma.value = "";
		document.form.programa.value = "";
	}

	function flimpiar2() {
		document.form.programa.value = "";
		document.form.secretaria.value = "";
	}

	function destino(target) {
		//alert(target);
		document.form.action = target;
		document.form.submit();
	}
 </script>

</head>
<body>


	<P></P>
	<P align="center"></P>
	<table cellspacing="1" cellpadding="2" border="0" width="80%"
		align="center">
		<tr>
			<td>
				<DIV align="center" class="titulosenblanco">ADMINISTRACI&Oacute;N&nbsp;DE&nbsp;BENEFICIOS</DIV>
			</td>
		</tr>
	</table>
	<br />
	<DIV align="center">
		<table width="90%" border="0" cellpadding="0" cellspacing="0"
			align="center">
			<tr>
				<td>
					<table width="90%" border="0" cellpadding="0" cellspacing="0"
						align="right">
						<tr />
						<tr>
							<td align="center">
								<html:link page="/subprogramas/IngresarSubprograma.do?ori=consulsub">
									<img src="<%=request.getContextPath() + "/images/b_nuevo.gif"%>"
										alt="Nuevo" width="22" height="22" border="0" />
									<br />
								</html:link> 
								<strong>Nuevo Beneficio</strong>
							</td>
							<td></td>
							<td></td>
							<td align="center">
								<html:link page="/subprogramas/ActivarSubprogramas.do?ori=activarsub">
									<img src="<%=request.getContextPath() + "/images/activar.gif"%>"
										alt="Activar" width="22" height="22" border="0" />
									<br />
								</html:link> 
								<strong>Activar Beneficio(s)</strong>
							</td>
							<td></td>
							<td></td>
							<!--<td align="center">
              <html:link page="/beneficios/RenovarMasiva.do">
                <img src="<%=request.getContextPath() + "/images/activar.gif"%>" alt="Renovacion Masiva" width="22" height="22" border="0"/>
                <br/>
              </html:link>
              <strong>Renovacion Masiva</strong>
            </td>-->
							<td align="center" width="25%"><input type="image"
								src="<%=request.getContextPath() + "/images/b_nuevo.gif"%>"
								alt="Asignar"
								onclick="destino('<%=request.getContextPath() + "/Sedes/UsuarioSubprograma.do"%>')" />
								<br /> <STRONG><span>Asignar Usuarios a un
										Beneficio</span> </STRONG></td>
						</tr>
					</table>
				</td>
			</tr>
		</table>
		<form name="form" method="GET"
			action="<%=request.getContextPath()
					+ "/subprogramas/ConsultarSubprograma.do"%>">
			<div align="center">
				<table class="tablaGenericaWidth100">
					<tr>
						<td width="17%" colspan="3" class="celdatabla" align="center">
							<P>Seleccione un criterio para la busqueda de beneficios</P>
						</td>
						<td width="11%"></td>
						<td></td>
					</tr>
					<tr>
						<td width="17%">&nbsp;</td>
						<td width="16%" class="celdatabla">
							<STRONG>Beneficio</STRONG>
						</td>
						<%
							Object strsubprograma = request.getParameter("subprograma");
							if (strsubprograma == null)
								strsubprograma = "";
						%>
						<td width="60%" align="left">
							<input type="text" class="formInputOutput300px" name="subprograma" value="<%=(String) strsubprograma%>"
								onchange="flimpiar2()" maxlength="50" size="50" />
						</td>
						<td width="11%">&nbsp;</td>
						<td>&nbsp;</td>
					</tr>
					<%						
						Collection<ProgramaVO> programas = (Collection<ProgramaVO>) request.getAttribute("programas");
						String strprograma = request.getParameter("programa");						
						if (programas != null) {
					%>
					<tr>
						<td width="17%">&nbsp;</td>
						<td class="celdatabla" width="16%">
							<STRONG>Programa</STRONG>
						</td>
						<td width="60%" align="left">
							<select name="programa" class="formInputOutput300px" onchange="flimpiar()">
								<option value="">SELECCIONE EL PROGRAMA</option>
								<%
									try {
											for (ProgramaVO vo: programas) {
												if (strprograma != null) {
													if (strprograma
															.equals(vo.getCode())) {
								%>
								<option selected="selected" value="<%=vo.getCode()%>"><%= vo.getNombre()%></option>
								<%
									} else {
								%>
								<option value="<%=vo.getCode()%>"><%=vo.getNombre()%></option>
								<%
									}
												} else {
								%>
								<option value="<%=vo.getCode()%>"><%=vo.getNombre()%></option>
								<%
									}
											}
								%>
							</select> <%
 	} catch (DAOException e) {
 		}
 		
 %>						</td>
						<td width="11%">&nbsp;</td>
						<td>&nbsp;</td>
					</tr>
					<%
						} else {
					%>
					<tr>
						<td width="17%">Ocurrio un error</td>
						<td width="16%">&nbsp;</td>
					</tr>
					<%
						}

						String strsecretaria = request.getParameter("secretaria");
						Collection<AreaVO> secretarias;	
						secretarias = (Collection<AreaVO>) request.getAttribute("secretarias");

						if (programas != null) {
					%>
					<tr>
						<td width="17%">&nbsp;</td>
						<td class="celdatabla" width="16%">
							<STRONG>Secretaria</STRONG>
						</td>
						<td align="left">
							<select name="secretaria" class="formInputOutput300px" onchange="flimpiar1()">
								<option value="">SELECCIONE LA SECRETARIA</option>
								<%
									try {
											for (AreaVO vo : secretarias) {
												if (strsecretaria != null) {
													if (strsecretaria.equals(vo.getCodearea())) {
								%>
								<option selected="selected" value="<%=vo.getCodearea()%>"><%=vo.getNombre()%></option>
								<%
									} else {
								%>
								<option value="<%=vo.getCodearea()%>"><%=vo.getNombre()%></option>
								<%
									}
												} else {
								%>
								<option value="<%=vo.getCodearea()%>"><%=vo.getNombre()%></option>
								<%
									}
											}
								%>
						</select> <%
 	} catch (DAOException e) {
 		e.printStackTrace();
 		}
 		
 %></td>
						<td width="11%">&nbsp;</td>
						<td>&nbsp;</td>
					</tr>
					<%
						} else {
					%>
					<tr>
						<td width="17%">Ocurrio un error</td>
						<td width="16%">&nbsp;</td>
					</tr>
					<%
						}
					%>
					<tr>
						<td width="17%">&nbsp;</td>
						<td width="16%"></td>
						<td width="42%"></td>
						<td width="11%">&nbsp;</td>
						<td>&nbsp;</td>
					</tr>
					<tr>
						<td colspan="4">
							<DIV align="center">
								<input type="submit" value="Consultar" onclick="fConsultar()"
									alt="Click para Consultar  Subprogramas" />
							</DIV>
						</td>
					</tr>

				</table>
			</div>

			<P>
				<%
					if (session.getAttribute("mensajes") != null) {
						out.println((String) session.getAttribute("mensajes"));
					}
					session.removeAttribute("mensajes");
				%>
			</P>
		</form>
	</DIV>
	<div align="center">
		<table class="tablaGenericaWidth90">
			<tr>
				<td><logic:notPresent scope="request" name="subprogramas">
						<DIV align="center"><%=request.getAttribute("msg")%></DIV>
					</logic:notPresent> <logic:present scope="request" name="subprogramas">
						<display:table name="requestScope.subprogramas"
							requestURI='<%=request.getContextPath()
							+ "/subprogramas/ConsultarSubprograma.do"%>'
							class="bordesTable" pagesize="20" id="subpro" cellpadding="3"
							cellspacing="1" style="width:100%">
							<bean:define id="Subprograma" name="subpro" property="code"></bean:define>
							<display:column headerClass="headerTable" title="Beneficio"
								class="Numero">
								<html:link paramId="Codigo" paramName="subpro"
									paramProperty="code"
									page="/subprogramas/ModificarSubprograma.do">
									<bean:write name="subpro" property="nombre" />
								</html:link>
							</display:column>
							<display:column headerClass="headerTable" title="Sedes Asociadas"
								class="Numero">
								<logic:equal name="subpro" property="tieneSede" value="N">
									<div align="center">
										<bean:write name="subpro" property="tieneSede" />
									</div>
								</logic:equal>
								<logic:notEqual name="subpro" property="tieneSede" value="N">
									<html:link paramId="Codigo" paramName="subpro"
										paramProperty="code" page="/subprogramas/SedesAsociadas.do">
										<div align="center">
											<bean:write name="subpro" property="tieneSede" />
										</div>
									</html:link>
								</logic:notEqual>
							</display:column>
							<display:column headerClass="headerTable" title="Modificar"
								class="Numero">
								<html:link paramId="Codigo" paramName="subpro"
									paramProperty="code"
									page="/subprogramas/ModificarSubprograma.do">
									<div align="center">
										<img
											src="<%=request.getContextPath()
									+ "/images/modificar.gif"%>"
											width="16" height="16" border="0">
									</div>
								</html:link>
							</display:column>
							<bean:define id="codigo" name="subpro" property="code"></bean:define>
							<%
								java.util.HashMap params = new java.util.HashMap();
										params.put("codigo", codigo);
										params.put("accion", "1");

										pageContext.setAttribute("parametros", params);
							%>
							<display:column headerClass="headerTable" title="Ver Usuarios"
								class="Numero">
								<html:link paramId="Codigo" paramName="subpro"
									paramProperty="code" page="/Beneficios/UsuariosxBeneficio.do">
									<div align="center">
										<img
											src="<%=request.getContextPath()
									+ "/images/usuario.gif"%>"
											width="16" height="16" border="0">
									</div>
								</html:link>
							</display:column>
							<%--  <display:column headerClass="headerTable" title="Ver Usuarios" class="Numero">
                       <html:link name="parametros" scope="page" page="/Beneficios/UsuariosxBeneficio.do">
                             <div align="center"><img src="<%= request.getContextPath() + "/images/usuario.gif" %>" width="16" height="16" border="0"></div>
                        </html:link>       
                    </display:column>	--%>
							<display:column headerClass="headerTable" title="Ver Atributos"
								class="Numero">
								<html:link name="parametros" scope="page"
									page="/BuscarAtributo.do">
									<div align="center">
										<img src="<%=request.getContextPath()
									+ "/images/ver.gif"%>"
											width="16" height="16" border="0">
									</div>
								</html:link>
							</display:column>
							<display:column headerClass="headerTable" title="Desactivar"
								class="Numero">
								<%--<bean:define id="Subprograma" name="subpro" property="code"></bean:define>--%>
								<div align="center">
									<a
										onclick="return confirm('¿Está seguro que desea desactivar el beneficio?');"
										href='javascript:vpopUsers("<%=request.getContextPath()
								+ "/jsp/subprogramas/RazonDesactivar.jsp"%>?Codigo=<%=Subprograma%>");'>

										<img
										src="<%=request.getContextPath()
								+ "/images/Delete.gif"%>"
										width="16" height="16" border="0">

									</a>
								</div>
							</display:column>
							<display:column headerClass="headerTable" title="Eliminar"
								class="Numero">
								<%--<bean:define id="Subprograma" name="subpro" property="code"></bean:define>--%>
								<div align="center">
									<a
										onclick="return confirm('¿Está seguro que desea eliminar el beneficio otorgado?');"
										href='javascript:vpopUsers("<%=request.getContextPath()
								+ "/jsp/subprogramas/RazonDesactivar.jsp"%>?Codigo=<%=Subprograma%>");'>

										<img
										src="<%=request.getContextPath()
								+ "/images/Delete.gif"%>"
										width="16" height="16" border="0">

									</a>
								</div>
							</display:column>
						</display:table>
					</logic:present></td>
			</tr>
		</table>
	</div>

</body>
</html>
